package com.hongyuan.sellfitness.ui.person.activity;

import android.os.Bundle;
import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityReservationLessonBinding;
import com.hongyuan.sellfitness.ui.person.view_mode.ReservationLessonViewModel;
import me.tatarka.bindingcollectionadapter2.BR;

public class ReservationLessonActivity extends CustomActivity<ActivityReservationLessonBinding, ReservationLessonViewModel> {

    private String my_course_id;
    private String cp_id;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_reservation_lesson;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public ReservationLessonViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(ReservationLessonViewModel.class);
    }

    @Override
    public void initParam() {
        super.initParam();
        cp_id = getBundle().getString("cp_id");
        my_course_id = getBundle().getString("my_course_id");
    }

    @Override
    public void initView() {
        super.initView();
        setOnRefresh(binding.refresh,REFRESH_0X4);

        binding.comBack.setOnClickListener(view -> finish());

        binding.selectTime.setViewModel(viewModel);
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("cp_id",cp_id).setParams("my_course_id",my_course_id);
        viewModel.requestData(Constants.GET_RESERVATION_LESSON_INFO);

    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

        viewModel.uc.setTimeTopData.observe(this, groupClassTopBeans -> {
            binding.selectTime.setTopData(groupClassTopBeans);
        });

        viewModel.uc.setTimeContentData.observe(this, coachidleTimeContentBeans -> {
            binding.selectTime.setContentData(coachidleTimeContentBeans);
        });

        viewModel.uc.reservation.observe(this, aVoid -> {
            //请求约课
            viewModel.clearParams().setParams("start_date",binding.selectTime.getStartTime())
                    .setParams("end_date",binding.selectTime.getEndTime())
                    .setParams("jl_mid",String.valueOf(viewModel.entity.get().getM_id()))
                    .setParams("num","1")
                    .setParams("cp_id",cp_id)
                    .setParams("my_course_id",my_course_id);

            viewModel.requestData(Constants.ADD_COURSE_PRIVITE_APPOINTMENT);
        });
    }
}
